package com.zerdoor.service.impl;

import com.zerdoor.dao.VipSetDao;
import com.zerdoor.service.VipSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by xiaoji on 2015/1/29.
 */
@Service
public class VipSetServiceImpl implements VipSetService {
    @Autowired
    private VipSetDao vipSetDao;

    /**
     * 用户等级管理
     *
     * @param id 父类编号
     * @return
     */
    @Override
    public List<Map<String, Object>> getVipSetInfo(int id) {
        return vipSetDao.getVipSetInfo(id);
    }

    /**
     * 添加用户等级
     *
     * @param map
     * @throws Exception
     */
    @Override
    public void addVipSet(Map<String, Object> map) throws Exception {
        vipSetDao.addVipSet(map);
    }

    /**
     * 编辑用户等级
     *
     * @param map
     * @throws Exception
     */
    @Override
    public void updateVipSet(Map<String, Object> map) throws Exception {
        vipSetDao.updateVipSet(map);
    }

    /**
     * 删除用户等级
     *
     * @param levelId 用户等级编号
     * @throws Exception
     */
    @Override
    public void deleteVipSet(int levelId) throws Exception {
        Map<String,Object> map = vipSetDao.getVipSetByPatentId(levelId);
        if(Integer.parseInt(map.get("total").toString()) >0){
            throw new Exception("此类下面有子类！删除失败。");
        }else{
            vipSetDao.deleteVipSet(levelId);
        }
    }
}
